package com.alan.server.service;

import com.alan.server.entity.DemoTest;
import com.alan.server.mapper.DemoTestMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Alan on 17-10-11
 */
@Service
public class TestService {

    @Autowired
    private IDemoTestService demoTestService;

    @Autowired
    private DemoTestMapper demoTestMapper;

    public String hello(String str){
        System.out.println(str);
        return "hello -- "+str;
    }
    public String hello2(String str,String tt2){
        System.out.println(str+tt2);
        return "hello -- "+str;
    }

    public List<DemoTest> selectAll(int page, int pagesize){
        PageHelper.startPage(page,pagesize);
        //ew 不能传null 不然分页逻辑删除有问题
        List<DemoTest> users = demoTestService.selectList(new EntityWrapper<DemoTest>().eq(DemoTest.USER_NAME,"aaa"));
        System.out.println(PageHelper.getTotal());
        System.out.println(PageHelper.getPagination());
        System.out.println(PageHelper.freeTotal());
        return users;
    }

    public Page<DemoTest> selectAll2(int pageNum, int pagesize){
        Page<DemoTest> page = new Page<>(pageNum,pagesize);
//        page.setRecords(testDataMapper.selectUserList(page, state));
        //ew 不能传null 不然分页逻辑删除有问题
        page = demoTestService.selectPage(page,new EntityWrapper<DemoTest>().eq(DemoTest.USER_NAME,"aaa"));
        return page;
    }

    public DemoTest select(Long id){
        DemoTest testData = demoTestService.selectById(id);
        System.out.println(testData);
        return testData;
    }

    public DemoTest select2(Long id){
        DemoTest testData = demoTestMapper.selectById(id);
        System.out.println(testData);
        return testData;
    }

    public DemoTest insert(DemoTest testData){
        System.out.println( demoTestService.insert(testData) );
        System.out.println(testData);
        return testData;
    }

    public void delete(Long id){
        System.out.println( demoTestMapper.deleteById(id) );
    }

    public void delete2(Long id){
        System.out.println( demoTestMapper.deleteById(id) );
    }

}
